package tt.dz.biz.service.user;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.user.RoleDAO;
import tt.dz.common.BusinessException;
import tt.dz.common.DzErrorCode;
import tt.dz.common.DzErrorCode.ExceptionErrorCode;
import tt.dz.common.LogUtil;
import tt.dz.vo.RoleVO;

@Service("roleService")
public class RoleService
{
  @Resource(name="roleDAO")
  RoleDAO roleDAO;
  
  public RoleVO queryRoleByID(String roleID, String sysCode)
  {
    return this.roleDAO.queryRoleByID(roleID, sysCode);
  }
  
  public List<RoleVO> queryRoleBySys(RoleVO roleVO)
  {
    List<RoleVO> roleList = null;
    try
    {
      roleList = this.roleDAO.queryRoleBySys(roleVO);
    }
    catch (Exception e)
    {
      LogUtil.error("查询角色列表异常--入参：" + roleVO.toString(), e);
      roleList = new ArrayList();
      
      throw new BusinessException(DzErrorCode.ExceptionErrorCode.COMMON_EXCEPTION.value(), DzErrorCode.ExceptionErrorCode.COMMON_EXCEPTION.getDesc(), e.getMessage());
    }
    return roleList;
  }
  
  public List<RoleVO> listAllRole()
  {
    List<RoleVO> roleList = null;
    try
    {
      roleList = this.roleDAO.listAllRole();
    }
    catch (Exception e)
    {
      LogUtil.error("查询角色列表异常", e);
      roleList = new ArrayList();
    }
    return roleList;
  }
  
  public List<RoleVO> listAllValidRole()
  {
    List<RoleVO> roleList = null;
    try
    {
      roleList = this.roleDAO.listAllValidRole();
    }
    catch (Exception e)
    {
      LogUtil.error("查询角色列表异常", e);
      roleList = new ArrayList();
    }
    return roleList;
  }
  
  public boolean insertRole(RoleVO roleVO)
  {
    boolean excuteFlag = false;
    try
    {
      int i = this.roleDAO.insertRole(roleVO);
      excuteFlag = i > 0;
    }
    catch (Exception e)
    {
      LogUtil.error("插入角色异常--入参：" + roleVO.toString(), e);
    }
    return excuteFlag;
  }
  
  public boolean updateRole(RoleVO roleVO)
  {
    boolean excuteFlag = false;
    try
    {
      int i = this.roleDAO.updateRole(roleVO);
      excuteFlag = i > 0;
    }
    catch (Exception e)
    {
      LogUtil.error("更新角色异常--入参：" + roleVO.toString(), e);
    }
    return excuteFlag;
  }
}
